package com.example.safeassistan.train.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.GridLayoutManager;

import com.example.safeassistan.R;
import com.example.safeassistan.base.BaseActivity;
import com.example.safeassistan.constants.UrlConstants;
import com.example.safeassistan.http.HttpRequest;
import com.example.safeassistan.http.HttpStringCallBack;
import com.example.safeassistan.train.adapter.PaperResultSingleAdapter;
import com.example.safeassistan.train.model.PaperResultModel;
import com.example.safeassistan.train.model.TrainTestListModel;
import com.example.safeassistan.utile.JsonUtils;

import org.json.JSONObject;

import java.io.Serializable;

public class TrainUnderstood  extends BaseActivity implements View.OnClickListener {
    private TextView tvStart,_barTvRight;
    private int type=1;
    private TrainTestListModel.ResultDTO.RecordsDTO data;
    private TextView tvPaperTitle,tvTotalTime,tvTotalScore;

    public static void actionStart(Context context, int type, TrainTestListModel.ResultDTO.RecordsDTO data) {
        Intent intent = new Intent(context, TrainUnderstood.class);
        intent.putExtra("type",type);
        intent.putExtra("data",(Serializable) data);
        context.startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tvStart:
                //开始答题
                if(type==1){
                    //1 模拟 2 考试
                    ActivitySimulateAnswerProblem.actionStart(getContext(),data.getId(),data.getUseTime()+"");
                }else {
                    ActivityTestAnswerProblem.actionStart(getContext(),data.getId());
                }
                break;
            case R.id._barTvRight:
                ActivityreportCard.actionStart(getContext(),data.getId());
                break;
        }
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_understood;
    }

    @Override
    protected void initView() {
        setTitleText("答题须知");
        type=getIntent().getIntExtra("type",0);
        data=(TrainTestListModel.ResultDTO.RecordsDTO) getIntent().getSerializableExtra("data");
        tvStart=findViewById(R.id.tvStart);
        tvStart.setOnClickListener(this::onClick);
        _barTvRight=findViewById(R.id._barTvRight);
        _barTvRight.setText("成绩单");
        _barTvRight.setTextColor(getResources().getColor(R.color.gray3));
        if(type==1){
            _barTvRight.setVisibility(View.VISIBLE);
        }else {
            _barTvRight.setVisibility(View.GONE);
        }
        _barTvRight.setOnClickListener(this::onClick);
        tvPaperTitle=findViewById(R.id.tvPaperTitle);
        tvTotalTime=findViewById(R.id.tvTotalTime);
        tvTotalScore=findViewById(R.id.tvTotalScore);

        setView();
    }

    //设置数据
    public void setView(){
        tvPaperTitle.setText(data.getPaperName());
        tvTotalTime.setText(data.getUseTime()+"分钟");
        tvTotalScore.setText(data.getTotalScore()+"分");

    }

    @Override
    protected void initData() {

    }
    @Override
    protected int getTitleBarType() {
        return 0;
    }
}
